{% extends "base.html" %}

{% block extra_head %}
{% endblock extra_head %}

{% block content %}
{% load i18n %}

<div class="bg-primary-gradient page-header">
  <div class="container">

    {% include "partials/messages.html" %}

    <div class="row">
      <div class="col-lg-8 col-lg-offset-2">

        <h1>Search the block chain</h1>
        <p class="lead">Find info that other block explorers don't have</p>

        <form role="search" method="post" action="{% url "home" %}">
          {% csrf_token %}
          <input type="hidden" value="btc" id="id_coin_symbol" name="coin_symbol">
          <input type="hidden" value="" id="search_filter" name="search_filter">

          <div class="input-group input-group-lg">
            <div class="input-group-btn">
              <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
                <span id="search-dropdown-label">BTC</span> <span class="caret"></span>
              </button>
              <ul class="dropdown-menu" role="menu">
                <li><a href="javascript:void(0);" onclick="setCoin('btc', 'BTC')">Bitcoin</a></li>
                <li><a href="javascript:void(0);" onclick="setCoin('eth', 'ETH')">Ethereum</a></li>
                <li><a href="javascript:void(0);" onclick="setCoin('btc-testnet', 'BTC Testnet')">Bitcoin Testnet</a></li>
                <li><a href="javascript:void(0);" onclick="setCoin('ltc', 'LTC')">Litecoin</a></li>
                <li><a href="javascript:void(0);" onclick="setCoin('doge', 'DOGE')">DogeCoin</a></li>
                <li><a href="javascript:void(0);" onclick="setCoin('dash', 'DASH')">Dash</a></li>
                <li><a href="javascript:void(0);" onclick="setCoin('bcy', 'BCY Testnet')">Blockcypher Testnet</a></li>
              </ul>
            </div>
            <input autofocus class="form-control" id="id_search_string" maxlength="128" name="search_string" type="search" placeholder="Example: 16Fg2yjwrbtC6fZp61EV9mNVKmwCzGasw5">
          </div>

          <p class="help-block search-filter">
            Enter an 
            <a href="javascript:void(0);" onclick="filterSearch('address', this)">address</a>,
            <a href="javascript:void(0);" onclick="filterSearch('tx_hash', this)">transaction hash</a>, 
            <a href="javascript:void(0);" onclick="filterSearch('block_hash', this)">block hash</a>,
            <a href="javascript:void(0);" onclick="filterSearch('block_num', this)">block number</a>, or 
            <a href="javascript:void(0);" onclick="filterSearch('wallet_name', this)">wallet name</a>.
          </p>

          <p class="text-center">
            <button type="submit" class="btn btn-primary btn-lg btn-xl">
              <i class="fa fa-search"></i> 
              {% trans "Search" %}
            </button>
          </p>

        </form>
      </div>
    </div>
  </div>
</div>

<div class="bg-white">
  <div class="container">
    <div class="ad">
      <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-8670884776365868"
             crossorigin="anonymous"></script>
      <!-- Main explorer -->
      <ins class="adsbygoogle"
             style="display:block;min-width:400px;max-width:970px;width:100%;height:90px"
                  data-ad-client="ca-pub-8670884776365868"
                       data-ad-slot="7521279835"></ins>
      <script>
             (adsbygoogle = window.adsbygoogle || []).push({});
      </script>
    </div>
  </div>

  <div class="container">

    <div class="row text-center">
      <h2>Browse the Blockchain</h2>
      <div class="col-lg-12">
        <div class="col-lg-3 col-md-3 col-sm-4 col-xs-4">
          <a href="{% url 'coin_overview' 'btc' %}" class="btc coin">
            <span class="mpsb">Bitcoin</span>
          </a>
        </div>
        <div class="col-lg-3 col-md-3 col-sm-4 col-xs-4">
          <a href="{% url 'coin_overview' 'eth' %}" class="eth coin">
            <span class="mpsb">Ethereum</span>
          </a>
        </div>
        <div class="col-lg-3 col-md-3 col-sm-4 col-xs-4">
          <a href="{% url 'coin_overview' 'ltc' %}" class="ltc coin">
            <span class="mpsb">Litecoin</span>
          </a>
        </div>
        <div class="col-lg-3 col-md-3 col-sm-4 col-xs-4">
          <a href="{% url 'coin_overview' 'doge' %}" class="doge coin">
            <span class="mpsb">Dogecoin</span>
          </a>
        </div>
        <div class="col-lg-3 col-md-3 col-sm-4 col-xs-4">
          <a href="{% url 'coin_overview' 'dash' %}" class="dash-logo coin">
            <span class="mpsb">Dash</span>
          </a>
        </div>
        <div class="col-lg-3 col-md-3 col-sm-4 col-xs-4">
          <a href="{% url 'coin_overview' 'bcy' %}" class="bc-testnet coin">
            <span class="mpsb">BlockCypher Testnet</span>
          </a>
        </div>
      </div>
    </div>

    <br />
    <br />
    <div class="row">
      <p class="text-center">
        Read more about what makes this block explorer different
        <a href="{% url 'highlights' %}">here</a>.
      </p>
    </div>

  </div>
</div>
{% endblock content %}

{% block extra_js %}
  <script>

    function filterSearch(filter, that) {
      //Update search input
      var coin_symbol_selected = $('#id_coin_symbol').val();
      var search_placeholders = {
        'btc': {
          'address': '16Fg2yjwrbtC6fZp61EV9mNVKmwCzGasw5',
          'wallet_name': 'sample.walletname.bit',
          'tx_hash': '2509e5b65ed362557fcf2104e89f3c2430ceecc6a3275556c1b966eb641fe092',
          'block_hash': '0000000000000000001e847e71b955482dab7228f4849a4659c0cf5cf323f247',
          'block_num': '330,027',
        },
        'eth': {
          'address': '0x9fece73db33be7b9a3d30b89fcc6a3f8e2bcf514',
          'wallet_name': 'sample.walletname.eth',
          'tx_hash': 'c4a5b198049c0d82c744800f46288abb04c1a60d429f05484bf084228f187577',
          'block_hash': '0d2bb8de3eba9937150b94f4ac03b29ba5b1478dfbd2af035b0e859d65b1721c',
          'block_num': '10,187,739',
        },
        'btc-testnet': {
          'address': '2N1rjhumXA3ephUQTDMfGhufxGQPZuZUTMk',
          'wallet_name': '',
          'tx_hash': '7f827d4a3ae3b6e408fa1737f12f9dbfa2bb8fd79e0e3e63256a6e78310790a4',
          'block_hash': '00000000b5017a924643958b430f073608142bf72a3cec1bfe30fed460246737',
          'block_num': '308,576',
        },
        'ltc': {
          'address': 'LcFFkbRUrr8j7TMi8oXUnfR4GPsgcXDepo',
          'wallet_name': 'sample.walletname.bit',
          'tx_hash': '3826e17bbac2724cd74b7377f0bd1489a82440d651016adda0132c42a179ad02',
          'block_hash': '515683dee4ea5ec9341450b4f6a6c9f842a75680e96ee130bf8605e785ad59ff',
          'block_num': '675,566',
        },
        'doge': {
          'address': 'D7Y55r6Yoc1G8EECxkQ6SuSjTgGJJ7M6yD',
          'wallet_name': 'sample.walletname.bit',
          'tx_hash': '28132b9676b227f16bb687f49139fbb38d185caba4533a8c36d49f0fa470d83a',
          'block_hash': '3c36f6b2abcc2e30111b997e551336db60bead9a0cd3c03fb192110bfbfe1841',
          'block_num': '460,882',
        },
        'dash': {
          'address': 'XdZW5Waa1i6D9za3qpFvgiwHzr8aFcXtNP ',
          'wallet_name': 'sample.walletname.bit',
          'tx_hash': 'a962e3b505d94d183c8eec832d56f0b7179564c91ed101b1f067d91ab34f5228',
          'block_hash': '0000000000003cbbbe719c094fa09a645006090844f913ef9da62c04b4de04c4 ',
          'block_num': '640,949',
        },
        'bcy': {
          'address': 'CFr99841LyMkyX5ZTGepY58rjXJhyNGXHf',
          'wallet_name': '',
          'tx_hash': '48cebffe1ed93ae2ce758abb52375cc7f89ecc94fd8244f6a9f6dd07463fc1cb',
          'block_hash': '0000a577e78b310c7a5fe75abfc70f8f638aa56aae33552955c2becf509cd19a',
          'block_num': '32,528',
        },
      }

      $('#id_search_string').val(search_placeholders[coin_symbol_selected][filter]);
      $('#search_filter').val(filter);

      $('.search-filter .active').removeClass('active');
      $(that).addClass('active');
    }

    $(document).ready(function(){

      $( "#id_search_string" ).keydown(function() {
        // Mark any suggestions as no longer a suggestion
        $('.search-filter .active').removeClass('active');
      });

      var ads = [];
      if (ads.length > 0) {
        var sites = {
          piiko: "https://www.piiko.co",
          texcent: "http://texcent.com",
					tradecore: "https://tradecore.com/"
        };
        var chosen_idx = Date.now() % ads.length;
        var chosen_ad = ads[chosen_idx];
        var track_url = "https://live.blockcypher.com/ads/"+chosen_ad;

        $('#ad-link img').attr("src", "/static/img/" + chosen_ad + "_ad.png");
        $('#ad-link').attr("href", sites[chosen_ad]);
        $('#ad-link').click(function(e) {
          ga('send', 'event', 'outbound', 'click', track_url, {
            'transport': 'beacon',
            'hitCallback': function() {
            setTimeout(function() {
              document.location = sites[chosen_ad];
            }, 200);
          }
          });
          e.preventDefault();
          e.stopPropagation();
        });
        $('div.ad').show();
      }
    })

  </script>
{% endblock extra_js %}
